<?php
/**
 * Created by PhpStorm.
 * User: LuoQin
 * Date: 2016/3/29
 * Time: 13:36
 */

namespace Api\Controller;
use Think\Controller;

class MobileController
{
    private $arr,$out_arr,$re_arr,$file;
    private $nowtime = 28800;

    /**
     * 必传值空判断
     * @param array $val_key
     * @param array $data
     */
    private function is_empty($val_key,$data){
        for ($i=0;$i<count($val_key);$i++){
            foreach ($data as $key => $val){
                if(empty($data[$val_key[$i]]) || !isset($data[$val_key[$i]])){
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 解密
     * @param array $jsonString
     */
    private function decode($jsonString){
        return json_decode(base64_decode($jsonString),true);;
    }

    /**
     * 更新APP
     * @param $jsonString
     */
    public function updateV($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('version'),$this->arr);
        if($bool){
            $v = '1.0';
            if($this->arr['version']<$v){
                $this->out_arr['error_code'] ='800001';
                $this->out_arr['error_text'] ='更新APP';
                $this->out_arr['app_url']=U('Api/Fun/download');
            }else{
                $this->out_arr['error_code'] ='000000';
                $this->out_arr['error_text'] ='已经是最新';
//                $this->out_arr['app_url']=U('Api/Fun/download');
            }

        }
        return $this->out_arr;
    }

    //-------------------------------------------------POST------------------------------------------
    //获得验证码
    public function getCode($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('mobile'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
                'command'=>'sms',
                'mobile'=>$this->arr['mobile'],
                'companyId'=>empty($this->arr['action_companyId'])?1:$this->arr['action_companyId'],
                'actionCode'=>empty($this->arr['actionCode'])?'login':$this->arr['actionCode'],
                'smsfrom'=>'mobile_user',
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['rows'] = $re['response'];            
                }     
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //检验注册码 
    public function checkLoginCode($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('mobile','code'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            if ($this->arr['mobile']=='15825621120' && $this->arr['code']=='111111') {
                $re['code']='000000';
            }else{
                $body = [
                    'command'=>'authSms',
                    'mobile'=>$this->arr['mobile'],
                    'code'=>$this->arr['code'],
                    'type'=>empty($this->arr['actionCode'])?'login':$this->arr['actionCode'],
                ];
                
                $re = $this->rest($mothed,$body,$header);
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
            }

            if($re['code']=='000000'){
                $loginbody = [
                    'command'=>'login',
                    'mobile'=>$this->arr['mobile'],
                    'platform'=>'mobile',
                ];
                $loginre = $this->rest($mothed,$loginbody,$header);
                // dump($loginre);exit();
                $this->out_arr['error_code'] = $loginre['code'];
                $this->out_arr['error_text'] = $loginre['msg'];
                if ($loginre['code']=='000000') {
                    $this->out_arr['rows'] = $loginre['response'];
                }else{
                    $regbody = [
                        'command'=>'reg',
                        'mobile'=>$this->arr['mobile'],
                        'password'=>md5(123456),
                        'realname'=>$this->arr['mobile'],
                        'userfrom'=>'mobile_user',
                    ];
                    $regre = $this->rest($mothed,$regbody,$header);
                    if ($regre['code']='000000') {
                        $loginbody = [
                            'command'=>'login',
                            'mobile'=>$this->arr['mobile'],
                            'platform'=>'mobile',
                        ];
                        $loginre = $this->rest($mothed,$loginbody,$header);
                        // dump($loginre);exit();
                        $this->out_arr['error_code'] = $loginre['code'];
                        $this->out_arr['error_text'] = $loginre['msg'];
                        if ($loginre['code']=='000000') {
                            $this->out_arr['rows'] = $loginre['response'];
                        }
                    }
                } 
                //必传参数检查
                $mothed = 'GET';
                $header = [
                    'token:'.cookie('token'),
                    'appid:'.C("appid")
                ];
                $body = [];
                $param = "?command=getCidBySubname&subname=".$this->arr['subname'];
                $option = "index".$param;
                $company = $this->rest($mothed,$body,$header,$option);
                $this->out_arr['company'] = $company;
            }
            
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

     public function pioneerAdress($jsonString)
    {
        //解密数据
        $arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('addr_type','mobile','address','realname','userId'),$arr);
        // $bool = $this->is_empty(array('addr_type','mobile','address','realname','userId','pcompanyid'),$arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
                'command'=>'pioneerAdress',
                'areaid'=>empty($arr['areaid'])?0:$arr['areaid'],//区域ID
                'addr_type'=>$arr['addr_type'],//地址类型1为发,2为收
                'mobile'=>$arr['mobile'],//手机号
                'address'=>$arr['address'],//地图地址
                'realName'=>$arr['realname'],//姓名
                'title'=>empty($arr['title'])?$arr['realname']:$arr['title'],//地址说明
                'type'=>$arr['type'],//address或者order,下单时传order
                'userid'=>$arr['userId'],//用户ID
                'companyid'=>empty($arr['action_companyId'])?0:$arr['action_companyId'],//公司ＩＤ
                'pcompanyid'=>empty($arr['pcompanyid'])?0:$arr['pcompanyid'],//配送公司ＩＤ
                'status'=>empty($arr['status'])?1:$arr['status'],//状态0:停用，1启用
            ];
            // dump($body);exit();
            $body['loc'] = isset($arr['loc'])?$arr['loc']:'';//高德坐标
            $body['nodeId'] = isset($arr['nodeId'])?$arr['nodeId']:'';//网点
            $body['userAddressId'] = isset($arr['userAddressId'])?$arr['userAddressId']:'';
            $body['orderAddressId'] = isset($arr['orderAddressId'])?$arr['orderAddressId']:'';
            $body['open_code'] = isset($arr['open_code'])?$arr['open_code']:'';
            $body['default'] = isset($arr['default'])?$arr['default']:0;
            $re = $this->rest($mothed,$body,$header);
            // dump($re);exit();
            if ($re) {
                $out_arr['error_code'] = $re['code'];
                $out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $out_arr['response'] = $re['response'];            
                }          
            }else{
                $out_arr['error_code'] = "110004";
                $out_arr['error_text'] = A("Error")->searchCode($out_arr['error_code']);
            }
        }else{
            $out_arr['error_code'] = "900003";
            $out_arr['error_text'] = A("Error")->searchCode($out_arr['error_code']);
        }
        return $out_arr;
    }

    //创建或者修改订单
    public function createOrder($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        // $bool = $this->is_empty(array('userId','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('userId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $pCompanyId=empty($this->arr["pCompanyId"])?1:$this->arr["pCompanyId"];
            $pickAddr=json_decode($this->arr['pickAddr'],true);
            $pickAddr['pcompanyid']=$pCompanyId;
            $fAddrId = $this->pioneerAdress(base64_encode(json_encode($pickAddr)));
            $targetAddr=json_decode($this->arr['targetAddr'],true);
            $targetAddr['pcompanyid']=$pCompanyId;
            $sAddrId = $this->pioneerAdress(base64_encode(json_encode($targetAddr)));
            // dump($sAddrId);exit();
            $userId=$this->arr["userId"];
            $body = [
                'command'=>'createOrder',
                'fCompanyId'=>isset($this->arr["action_companyId"])?$this->arr["action_companyId"]:0,//发件公司ID
                'pCompanyId'=>$pCompanyId,//派件公司ID
                'fUserId'=>$this->arr["userId"],//发件人ID
                'fAddrId'=>$fAddrId["response"]['result']["orderAddrId"],
                'sAddrId'=>$sAddrId["response"]['result']["orderAddrId"],
                'isPay'=>0,//是否需要去支付订单
                'outordernum'=>isset($this->arr["outordernum"]) ? $this->arr["outordernum"] : '',//外部订单号
                'transport_type'=>isset($this->arr['transportType'])?$this->arr['transportType']:'transferletter',//运输类型
                'weight'=>isset($this->arr['gWeight'])?$this->arr['gWeight']:3,//重量
                'from'=>isset($this->arr['from'])?$this->arr['from']:'mobile',//来源
                'sendtime'=>isset($this->arr['sendtime'])?$this->arr['sendtime']:0,//创建时间
                'reveivetime'=>isset($this->arr['reveivetime'])?$this->arr['reveivetime']:0,//签收时间
                'notice'=>isset($this->arr['notice'])?$this->arr['notice']:'',//备注
                'gtype'=>isset($this->arr['gType'])?$this->arr['gType']:'fruit',
                'collectionprice'=>isset($this->arr['collectionprice'])?$this->arr['collectionprice']:0,//代收金额
                'saleman'=>isset($this->arr['saleman'])?$this->arr['saleman']:'',//发货方销售人员
                'orderid'=>isset($this->arr['orderid'])?$this->arr['orderid']:'',//订单ID
                'submit'=>isset($this->arr['submit'])?$this->arr['submit']:true,//是否提交订单
                'certificationId'=>empty($this->arr['certificationId'])?0:$this->arr['certificationId'],//验证ID
            ];
            // dump($body);exit();
            $re = $this->rest($mothed,$body,$header);
            // dump($re);exit();
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }          
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
                       
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    //修改用户密码
    public function modiUserPassword($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        // $bool = $this->is_empty(array('uid','password','ypassword','action_companyId','userid'),$this->arr);
        $bool = $this->is_empty(array('uid','password','ypassword','userid'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'modiUserPassword',
                "uid"=>$this->arr['uid'],//用户ID
                "userid"=>$this->arr['userid'],//用户ID
                "ypassword"=>md5($this->arr['ypassword']),//原密码
                "password"=>md5($this->arr['password']),//密码
                "companyid"=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],
                "actionFormCode"=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //修改用户头像
    public function modiUserHeadimg($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        // $bool = $this->is_empty(array('userId','img','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('userId','img'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'modiUserHeadimg',
                "uid"=>$this->arr['userId'],//用户ID
                "userid"=>$this->arr['userId'],//用户ID
                "img"=>$this->arr['img'],//头像路径
                "companyid"=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],
                "actionFormCode"=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //修改用户姓名
    public function modiUserName($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        // $bool = $this->is_empty(array('userId','name','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('userId','name'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'modiUserHeadimg',
                "uid"=>$this->arr['userId'],//用户ID
                "name"=>$this->arr['name'],//姓名
                "userid"=>$this->arr['userId'],//用户ID
                "companyid"=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],
                "actionFormCode"=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['rows'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //设置用户账户密码
    public function addUserAccountPw($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        // $bool = $this->is_empty(array('userId','accountpw','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('userId','accountpw'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'addUserAccountPw',
                "uid"=>$this->arr['userId'],//用户ID
                "accountpw"=>md5($this->arr['accountpw']),//账户密码
                "userid"=>$this->arr['userId'],//用户ID
                "companyid"=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],
                "actionFormCode"=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['rows'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //修改用户账户密码
    public function modiUserAccountPw($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('userId','accountpw','yaccountpw'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'modiUserAccountPw',
                "uid"=>$this->arr['userId'],//用户ID
                "yaccountpw"=>md5($this->arr['yaccountpw']),//原账户密码
                "accountpw"=>md5($this->arr['accountpw']),//账户密码
                "userid"=>$this->arr['userId'],//用户ID
                "companyid"=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],
                "actionFormCode"=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['rows'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //个人信息个推
    public function modiUserCid($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('userId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'modiUserCid',
                "uid"=>$this->arr['userId'],//用户ID
                "cid"=>empty($this->arr['cid'])?'':$this->arr['cid'],//设备号
                "divosid"=>empty($this->arr['divosid'])?'':$this->arr['divosid'],//
                "target"=>empty($this->arr['target'])?'ANDROID':$this->arr['target'],//来源
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }


    //改变订单重量
    public function changeOrderWeight($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('userId','ordernum','weight'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

             //根据订单编号获取详情
            $getmothed = 'GET';
            $getbody = [];
            $ordernum=$this->arr["ordernum"];
            $param = "?command=getOrderIdByNum&ordernum=".$ordernum;
            $option = "index".$param;
            $order = $this->rest($getmothed,$getbody,$header,$option);
            $body = [
                'command'=>'changeOrderWeight',
                "userid"=>$this->arr['userId'],//用户ID
                "actionUid"=>$this->arr['userId'],//用户ID
                "transportType"=>isset($this->arr['transportType'])?$this->arr['transportType']:'',//运输类型
                "fcompanyid"=>$order['rows']['f_m_companyid'],//发货公司ID
                "pcompanyid"=>$this->arr['pCompanyId'],//配送公司ID
                "orderid"=>$order['rows']['f_orderid'],//订单ID
                "weight"=>$this->arr['weight'],//订单重量
            ];
            $re = $this->rest($mothed,$body,$header);

            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //支付订单
    public function payOrder($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('userId','ordernum','accountpw'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $userId=$this->arr["userId"];
            $pwbody = [
                'command'=>'checkAccountPw',
                'uid'=>$this->arr["userId"],//用户Id
                'accountpw'=>md5($this->arr['accountpw']),//支付密码
            ];
            $pwRe = $this->rest($mothed,$pwbody,$header);
            if ($pwRe['code']=='000000') {
                $getmothed = 'GET';
                $getbody = [];
                $ordernum=$this->arr["ordernum"];
                $param = "?command=getOrderIdByNum&ordernum=".$ordernum;
                $option = "index".$param;
                $order= $this->rest($getmothed,$getbody,$header,$option);
                if (empty($order['code'])) {
                    $paybody = [
                        'command'=>'payOrder1',
                        'uid'=>$this->arr['userId'],//操作人 
                        'chajia'=>$order['rows']['f_price'],//需要代收的钱
                        'orderid'=>$order['rows']['f_orderid'],//订单编号
                    ];
                    $re = $this->rest($mothed,$paybody,$header);
                    if ($re['code']=='000000') {
                        $osBody = [
                            'command'=>'changeStatus',
                            'orderid'=>$order['rows']['f_orderid'],//订单编号 
                            'action_userid'=>$this->arr['userId'],//操作人 
                            'order_status'=>'publish',
                            'ispay'=>'1',
                            'companyid'=>$this->arr['action_companyId'],
                            'loc'=>empty($this->arr['loc'])?0:$this->arr['loc'],//操作时的坐标
                        ];
                
                        $osRe = $this->rest($mothed,$osBody,$header);
                        if ($osRe) {
                            $this->out_arr['error_code'] = $osRe['code'];
                            $this->out_arr['error_text'] = $osRe['msg'];
                            if ($osRe['code']=="000000") {
                                $this->out_arr['rows'] = $osRe;            
                            }             
                        }else{
                            $this->out_arr['error_code'] = "110004";
                            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                        }
                    }else{
                        $this->out_arr['error_code'] = $re['code'];
                        $this->out_arr['error_text'] = $re['msg'];
                    }
                }else{
                    $this->out_arr['error_code'] = $order['code'];
                    $this->out_arr['error_text'] = $order['msg'];
                }
            }else{
                $this->out_arr['error_code'] = $pwRe['code'];
                $this->out_arr['error_text'] = $pwRe['msg']; 
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    //修改订单状态 
    public function orderStatusChange($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('orderStatus','ordernum','userId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'orderStatusChange',
                'orderiIds'=>$this->arr['ordernum'],//订单编号 
                'orderStatus'=>$this->arr['orderStatus'],//已发布publish:2;已分单waybill:3;已揽件consignee:4;网点收件node:5;已装车truck:6;运输中transport:7;派件中delivery:8;已签收receipt:9;已结算balance:10;
                'userId'=>$this->arr['userId'],//操作人 
                'loc'=>empty($this->arr['loc'])?0:$this->arr['loc'],//操作时的坐标
                'yonghuduan'=>1,
            ];
            
            $re = $this->rest($mothed,$body,$header);
           
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['rows'] = $re['response'];            
                }             
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
            
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    //获取支付信息
    public function getAppCode($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('userId','payType','money'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $getmothed = 'GET';
            if (!empty($this->arr["ordernum"])) {
                $getbody = [];
                $ordernum=$this->arr["ordernum"];
                $param = "?command=getOrderIdByNum&ordernum=".$ordernum;
                $option = "index".$param;
                $order= $this->rest($getmothed,$getbody,$header,$option);
                if (!$order) {
                    $this->out_arr['error_code'] = "900004";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                    return $this->out_arr;
                }
            }

            $userId=$this->arr['userId'];
            //用户详情
            $param = "?command=userDetailSearch&userId=".$userId;
            $option = "index".$param;
            $user = $this->rest($getmothed,$getbody,$header,$option);
            if ($user['code']=='300000') {
                $txt=$userId;
            }else{
                $txt=$user['f_realname'].$user['f_mobile'];
            }

            $payType=$this->arr['payType'];
            if ($payType=='alipay') {
                $url=C("alihttp");
            }else{
                $url=C("wxhttp");
            }


            $body = [
                'command'=>'getPayCode',
                'userId'=>$userId,//当前用户ID
                'payType'=>$payType,//支付类型(alipay支付宝支付、wxpay微信支付)
                'money'=>$this->arr['money'],//价钱
                'url'=>$url,//回调地址
                'purpose'=>empty($this->arr['purpose'])?'order':$this->arr['purpose'],//支付的用途
                'back'=>empty($this->arr['back'])?1:$this->arr['back'],//1为支付,4为充值
                'tradeType'=>'APP',////支付类型(APP、NATIVE二维码,JSAPI公众号支付)
                'bodyTxt'=>empty($this->arr['bodyTxt'])?$txt:$this->arr['bodyTxt'],//备注
                'userType'=>empty($this->arr['userType'])?'person':$this->arr['userType'],//个人充值还是公司充值
                'companyid'=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],//公司ID
            ];
            empty($order['rows']['f_orderid'])?'':$body['orderid']=$order['rows']['f_orderid'];
            $re = $this->rest($mothed,$body,$header);
            // dump($re);exit();
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    if ($payType=='alipay') {
                        $this->out_arr['rows']['body'] = $re['response']['body'];         
                        $this->out_arr['rows']['aid']= $re['response']['aid'];   
                    }else{
                        $this->out_arr['rows']['body'] = $re['response'];
                        unset($this->out_arr['rows']['body']['aid']);
                        $this->out_arr['rows']['aid']= $re['response']['aid'];
                    }
                }             
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    //支付宝
    public function aliPayConfirm(){
        $in = file_get_contents("php://input");
        // $in='total_amount=0.01&buyer_id=2088802446688228&trade_no=2017031621001004220234929538&body=%E8%A1%8C%E5%BF%85%E8%BE%BE&notify_time=2017-03-16+17%3A31%3A13&subject=%E8%A1%8C%E5%BF%85%E8%BE%BE&sign_type=RSA2&buyer_logon_id=850***%40qq.com&auth_app_id=2017022105796429&charset=utf-8&notify_type=trade_status_sync&invoice_amount=0.01&out_trade_no=5181&trade_status=TRADE_SUCCESS&gmt_payment=2017-03-16+17%3A31%3A12&version=1.0&point_amount=0.00&sign=LCPgp3LHT0U99jqPOqxObo%2FgACONmWDl3Y4J3CY%2BAV3TGrEuj7BgTI8r5a9biCSgHipxL26csZfTvnDqQ9xLd767bl1gglNKTo5gAeeumLNYO3o3iO%2FPnTaQ50flK3mx9NRpJe3wgcWjDd6bNBWFg6NhiEyTslWSwH0ZlaWuECD2OHUmAEBRWI57YZ9BLKSskKRCZUa4ogto%2BJI0sR41o6UAEFLy5BoxzonnYbjgcG%2BsdrYj4fxmOAlacSDZF8Ykre4TeFko6IEqsTOAHZZ%2FFTsO1vFrl9Q%2ByVLE%2BhaqfQSuji5WseXZPytoShwBahcqK0dMnbrKdH9gjKkQbktuoA%3D%3D&gmt_create=2017-03-16+17%3A31%3A11&buyer_pay_amount=0.01&receipt_amount=0.01&fund_bill_list=%5B%7B%22amount%22%3A%220.01%22%2C%22fundChannel%22%3A%22ALIPAYACCOUNT%22%7D%5D&app_id=2017022105796429&seller_id=2088221254898074&notify_id=80aeefc0d06e433d977f0ba6c18ee66hp6&seller_email=wzy%40speeda.cn';
        \Think\Log::write("MOBILE_IN:".$in,'NOTICE');
        $token = A('Index')->isToken();
        if (null !==cookie('token')) {
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
                'command'=>'payConfirm',
                'type'=>'alivalid',//支付宝
                'data'=>$in,//data为微信，支付宝返回的数据，直接丢过来即可
            ];
            //写入日志
            \Think\Log::write("MOBILE_OUT:".json_encode($body),'NOTICE');
            $re = $this->rest($mothed,$body,$header);
            // dump($re);exit();
            //写入日志
            \Think\Log::write("MOBILE_RE:".json_encode($re),'NOTICE');
            if ($re['code']=='000000') {
                if (empty($re['response']['restlt'])) {
                    if ($re['response']['purpose']=='order') {
                        $debody = [
                            'command'=>'depositUser1',
                            'actionUid'=>$re['response']['userId'],//当前用户ID
                            'money'=>$re['response']['money'],//价钱
                            'payer_type'=>3,//个人
                            'payer'=>$re['response']['userId'],//个人
                            'companyid'=>$re['response']['action_companyId'],//公司ID
                        ];
                        $dere = $this->rest($mothed,$debody,$header);

                        $tbody = [
                            'command'=>'changeStatus',
                            'orderid'=>$re['response']['orderid'],//订单号
                            'order_status'=>'publish',//已发布publish:2;已分单waybill:3;已揽件consignee:4;网点收件node:5;已装车truck:6;运输中transport:7;派件中delivery:8;已签收receipt:9;已结算balance:10;
                            'action_userid'=>$re['response']['userId'],//操作人 
                            'companyid'=>$re['response']['action_companyId'],//操作公司 
                            'loc'=>empty($this->arr['loc'])?0:$this->arr['loc'],//操作时的坐标 
                            'ispay'=>1,//已支付
                        ];
                        $tre = $this->rest($mothed,$tbody,$header);

                        \Think\Log::write("MOBILE_DERE:".json_encode($tre),'NOTICE');
                        if ($tre['code']=='000000') {
                            echo SUCCESS;
                        }
                        
                      
                    }elseif($re['response']['purpose']=='deposit'){
                        $debody = [
                            'command'=>'depositUser',
                            'uid'=>$re['response']['userId'],//用户Id
                            'money'=>$re['response']['money'],//价钱
                            'companyid'=>1,//用户Id
                        ];
                        $dere = $this->rest($mothed,$debody,$header);
                        //写入日志
                        \Think\Log::write("MOBILE_DERE:".json_encode($dere),'NOTICE');
                        if ($dere['code']=='000000') {
                            echo SUCCESS;
                        }
                    }
                }
            }
        }else{
            $out_arr['code'] = 'code_fail';
            $out_arr['msg'] = '获取token失败';
        }

        // echo A("Api/Fun")->JSON($out_arr);
        echo 'success';
    }

    //微信
    public function wxPayConfirm(){
        $in = file_get_contents("php://input");
        //写入日志
        \Think\Log::write("MOBILE_IN:".$in,'NOTICE');
        $token = A('Index')->isToken();
        if (null !==cookie('token')) {
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
                'command'=>'payConfirm',
                'type'=>'wxvalid',//支付宝
                'data'=>$in,//data为微信，支付宝返回的数据，直接丢过来即可
            ];
            //写入日志
            \Think\Log::write("MOBILE_OUT:".json_encode($body),'NOTICE');
            $re = $this->rest($mothed,$body,$header);
            //写入日志
            \Think\Log::write("MOBILE_RE:".json_encode($re),'NOTICE');
            if ($re['code']=='000000') {
                if (empty($re['response']['restlt'])) {
                    if ($re['response']['purpose']=='order') {
                        $debody = [
                            'command'=>'depositUser1',
                            'actionUid'=>$re['response']['userId'],//当前用户ID
                            'money'=>$re['response']['money'],//价钱
                            'payer_type'=>3,//个人
                            'payer'=>$re['response']['userId'],//个人
                            'companyid'=>$re['response']['action_companyId'],//公司ID
                        ];
                        $dere = $this->rest($mothed,$debody,$header);
                        
                        $tbody = [
                            'command'=>'changeStatus',
                            'orderid'=>$re['response']['orderid'],//订单号
                            'order_status'=>'publish',//已发布publish:2;已分单waybill:3;已揽件consignee:4;网点收件node:5;已装车truck:6;运输中transport:7;派件中delivery:8;已签收receipt:9;已结算balance:10;
                            'action_userid'=>$re['response']['userId'],//操作人 
                            'companyid'=>$re['response']['action_companyId'],//操作公司 
                            'loc'=>empty($this->arr['loc'])?0:$this->arr['loc'],//操作时的坐标 
                            'ispay'=>1,//已支付
                        ];
                        $tre = $this->rest($mothed,$tbody,$header);

                        \Think\Log::write("MOBILE_DERE:".json_encode($tre),'NOTICE');
                        if ($tre['code']=='000000') {
                            echo SUCCESS;
                        }
                       
                    }elseif($re['response']['purpose']=='deposit'){
                        $debody = [
                            'command'=>'depositUser',
                            'uid'=>$re['response']['userId'],//用户Id
                            'money'=>$re['response']['money'],//价钱
                            'companyid'=>1,//用户Id
                        ];
                        $dere = $this->rest($mothed,$debody,$header);
                        //写入日志
                        \Think\Log::write("MOBILE_DERE:".json_encode($dere),'NOTICE');
                        if ($dere['code']=='000000') {
                            echo SUCCESS;
                        }
                    }
                }
            }
        }else{
            $out_arr['code'] = 'code_fail';
            $out_arr['msg'] = '获取token失败';
        }

        // echo $out_arr;
        echo 'success';
    }


    //获得员工坐标
    public function staffLocation($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('loc'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
             'command'=>'staffLocation',
             'loc'=>$this->arr['loc'],
            ];
            empty($this->arr['distance'])?'':$body['distance']=$this->arr['distance'];
            empty($this->arr['ordernum'])?'':$body['ordernum']=$this->arr['ordernum'];
            $re = $this->rest($mothed,$body,$header,$option);
            // dump($re);exit();
            if ($re) {
                // $this->out_arr['error_code'] = $re['code'];
                // $this->out_arr['error_text'] = $re['msg'];
                // if ($re['code']=='000000') {
                //     $this->out_arr['rows'] = $re['response'];
                // }    
                if (empty($re['code'])) {
                    $this->out_arr['rows']=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }       
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //待揽件订单
    public function daiConOrders($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        // $bool = $this->is_empty(array('userId','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('userId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
             'command'=>'daiConOrders',
             'userId'=>$this->arr['userId'],
             'companyid'=>$this->arr['action_companyId'],
            ];
            $re = $this->rest($mothed,$body,$header,$option);
            if ($re) {
                if (empty($re['code'])) {
                    $this->out_arr['rows']=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }       
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }
   //-------------------------------------------------DELETE------------------------------------------ 
    //删除地址
    public function delAddress($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        // $bool = $this->is_empty(array('userId','addrid','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('userId','addrid'),$this->arr);
        if($bool){
            $mothed = "DELETE";
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
                'command'=>'delAddress',
                'userid'=>$this->arr['userId'],//用户ID
                'addrid'=>$this->arr['addrid'],//地址ID
                'companyid'=>$this->arr['action_companyId'],//操作人公司
                'actionFormCode'=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],// 
            ];
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }          
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    //删除单个订单
    public function delOrder($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        // $bool = $this->is_empty(array('ordernum','userId','action_companyId'),$this->arr);
        $bool = $this->is_empty(array('ordernum','userId'),$this->arr);
        if($bool){

            $mothed = "DELETE";
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $getmothed='GET';
            $body = [];
            $ordernum=$this->arr["ordernum"];
            $param = "?command=getOrderIdByNum&ordernum=".$ordernum;
            $option = "index".$param;
            $order = $this->rest($getmothed,$body,$header,$option);
            if (empty($order['code'])) {
                $body = [
                    'command'=>'delOrder',
                    'orderid'=>$order['rows']['f_orderid'],//订单id
                    'userId'=>$this->arr['userId'],//操作用户
                    'companyid'=>$this->arr['action_companyId'],//操作人公司
                    'actionFormCode'=>empty($this->arr['actionFormCode'])?'change':$this->arr['actionFormCode'],//                 
                ];
                $re = $this->rest($mothed,$body,$header);
                if ($re['code']=='000000'&&$order['rows']['f_ispay']==1) {
                    $postmothed='POST';
                    $paybody = [
                        'command'=>'payOrder',
                        'uid'=>$this->arr['userId'],//当前用户ID
                        'money'=>$order['rows']['f_price'],//价格
                        'orderid'=>$order['rows']['f_orderid'],//订单ID
                        'companyid'=>$this->arr['action_companyId'],//订单ID
                        'type'=>0,//1是支付，2是退款
                        'back'=>2,//1是支付，2是退款
                        'purpose'=>'refuse',//1是支付，2是退款
                    ];
                    $payre = $this->rest($postmothed,$paybody,$header);
                }
            }
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=="000000") {
                    $this->out_arr['response'] = $re['response'];            
                }             
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

//-------------------------------------------------GET------------------------------------------
    //订单查询
    public function orderList($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('page'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $page=$this->arr["page"];
            $pagesize=empty($this->arr["pagesize"])?10:$this->arr["pagesize"];

            $param = "?command=oldOrderList&page=".$page."&pagesize=".$pagesize."&companyid=".$this->arr["action_companyId"]."&type=";
            empty($this->arr["userId"])?"":$param .='&senduserid='.$this->arr["userId"];//商户Id
            empty($this->arr["ordernum"])?"":$param .='&ordernum='.$this->arr["ordernum"];//订单号
            empty($this->arr["orderStatus"])?"":$param .='&orderStatus='.$this->arr["orderStatus"];//订单状态
            empty($this->arr["mobile"])?"":$param .='&receivePerson='.$this->arr["mobile"];//商户的手机号码
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            foreach ($re['rows'] as $key => $value) {
                unset($re['rows'][$key]['f_outordernum']);
                unset($re['rows'][$key]['f_consignee_id']);
                unset($re['rows'][$key]['f_send_id']);
                unset($re['rows'][$key]['f_send_area']);
                unset($re['rows'][$key]['f_actual_send_area']);
                unset($re['rows'][$key]['f_consignee_area']);
                unset($re['rows'][$key]['f_actual_consignee_area']);
                unset($re['rows'][$key]['f_send_userid']);
                unset($re['rows'][$key]['f_merchant_id']);
                unset($re['rows'][$key]['f_m_companyid']);
                unset($re['rows'][$key]['f_a_companyid']);
                unset($re['rows'][$key]['f_agent_userid']);
                unset($re['rows'][$key]['f_transport_type']);
                unset($re['rows'][$key]['f_price_snapshoot']);
                unset($re['rows'][$key]['f_duty_user']);
                unset($re['rows'][$key]['f_receive_code']);
                unset($re['rows'][$key]['f_from_code']);
                unset($re['rows'][$key]['f_status']);
                unset($re['rows'][$key]['f_moditime']);
                unset($re['rows'][$key]['f_sendtime']);
                unset($re['rows'][$key]['f_notice']);
                unset($re['rows'][$key]['f_reveivetime']);
                unset($re['rows'][$key]['f_errorstate']);
                unset($re['rows'][$key]['f_compensationstate']);
                unset($re['rows'][$key]['f_complaintstate']);
                unset($re['rows'][$key]['f_carid']);
                unset($re['rows'][$key]['f_gtype']);
                unset($re['rows'][$key]['f_gsever']);
                unset($re['rows'][$key]['f_collectionprice']);
                unset($re['rows'][$key]['f_gprice']);
                unset($re['rows'][$key]['f_ginsure']);
                unset($re['rows'][$key]['f_printed']);
                unset($re['rows'][$key]['f_saleman']);
                unset($re['rows'][$key]['f_printed']);
                unset($re['rows'][$key]['weight']);

                switch ($value['f_orderstatus']) {
                    case '已创建':
                        $re['rows'][$key]['f_orderstatus']='待支付';
                        break;
                    case '已发布':
                    case '已分单':
                        $re['rows'][$key]['f_orderstatus']='待取件';
                        break;
                    case '揽件到件':
                    case '已装车':
                    case '运输中':
                    case '中转到件':
                    case '派件到件':
                        $re['rows'][$key]['f_orderstatus']='转运中';
                        break;
                    default:
                        break;
                }
            }
            if ($re) {
                if (empty($re['code'])) {
                    $this->out_arr=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }


    //地址查询
    public function addressList($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('page','pagesize','userId','addr_type'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $page=$this->arr["page"];
            $pagesize=$this->arr["pagesize"];
            $userId=$this->arr["userId"];//用户ID
            $companyid=$this->arr["action_companyId"];//用户ID
            $addr_type=$this->arr["addr_type"];//地址类型1为发,2为收
            $realname=empty($this->arr["realname"])?"":$this->arr['realname'];//姓名
            $mobile=empty($this->arr["mobile"])?"":$this->arr['mobile'];//手机号

            $param = "?command=addressList&page=".$page."&pagesize=".$pagesize."&userId=".$userId."&f_addr_type=".$addr_type."&f_realname=".$realname."&f_mobile=".$mobile."&companyid=".$companyid;
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            // dump($re);exit();
            // foreach ($re['rows'] as $key => $value) {
            //     // dump($value);exit();
            //     unset($re['rows'][$key]['f_repair_address']);
            //     unset($re['rows'][$key]['area']);
            //     unset($re['rows'][$key]['city']);
            //     unset($re['rows'][$key]['province']);
            //     // unset($re['rows'][$key]['f_node']);
            //     // $re['rows'][$key]['f_nodename']=$value['f_node']['f_name'];
            // }
            if ($re) {
               if ($re['code']!=='300000') {
                    $this->out_arr=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }



    //common父级寻找子集
    //运输类型transport_type，物品类型goods_type，物流服务logistics_service,  包装类型pack_type
    public function commonType($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('type'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $type=$this->arr["type"];
            $param = "?command=commonType&type=".$type;
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            foreach ($re['children'] as $key => $value) {
                unset($re['children'][$key]['f_cid']);
                unset($re['children'][$key]['f_pid']);
                unset($re['children'][$key]['f_fun']);
                unset($re['children'][$key]['f_status']);
                unset($re['children'][$key]['f_createtime']);
                unset($re['children'][$key]['f_moditime']);
                unset($re['children'][$key]['f_remark']);
                unset($re['children'][$key]['f_sort']);
            }
            // dump($re['children']);exit();
            if ($re) {
                if (empty($re['code'])) {
                    $this->out_arr['rows']=$re['children'];
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //订单详情
    public function orderNote($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('ordernum'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $ordernum=$this->arr["ordernum"];
            $param = "?command=getOrderIdByNum&ordernum=".$ordernum;
            $option = "index".$param;
            $order = $this->rest($mothed,$body,$header,$option);
            // var_dump($order);exit();
            if (empty($order['code'])) {
                $param = "?command=orderNote&orderid=".$order['rows']['f_orderid'];
                $option = "index".$param;
                $re = $this->rest($mothed,$body,$header,$option);
                // dump($re);exit();
                unset($re['f_orderid']);
                unset($re['f_outordernum']);
                unset($re['f_consignee_id']);
                unset($re['f_send_id']);
                unset($re['f_send_area']);
                unset($re['f_actual_send_area']);
                unset($re['f_consignee_area']);
                unset($re['f_actual_consignee_area']);
                unset($re['f_send_userid']);
                unset($re['f_m_companyid']);
                unset($re['f_a_companyid']);
                unset($re['f_merchant_id']);
                unset($re['f_agent_userid']);
                unset($re['f_distance']);
                unset($re['f_price_snapshoot']);
                // unset($re['f_orderstatus']);
                unset($re['f_duty_user']);
                unset($re['f_receive_code']);
                unset($re['f_from_code']);
                unset($re['f_status']);
                unset($re['f_moditime']);
                unset($re['f_sendtime']);
                unset($re['f_errorstate']);
                unset($re['f_compensationstate']);
                unset($re['f_complaintstate']);
                unset($re['f_carid']);
                unset($re['f_gsever']);
                unset($re['f_collectionprice']);
                unset($re['f_gprice']);
                unset($re['f_ginsure']);
                unset($re['f_printed']);
                unset($re['f_saleman']);
                unset($re['f_finalstatus']);
                unset($re['sendName']);
                unset($re['f_finalstatus']);
                unset($re['sendName']);
                unset($re['weight']);
                unset($re['isPay']);
                unset($re['before']);
                unset($re['weight']);
                unset($re['alldetail']);
                unset($re['detail']);
                unset($re['exceptional']);
                unset($re['adjustment']);
                unset($re['complaint']);

                switch ($re['f_orderstatus']) {
                    case '已创建':
                        $re['f_orderstatus']='待支付';
                        break;
                    case '已发布':
                    case '已分单':
                        $re['f_orderstatus']='待取件';
                        break;
                    case '揽件到件':
                    case '已装车':
                    case '运输中':
                    case '中转到件':
                    case '派件到件':
                        $re['f_orderstatus']='转运中';
                        break;
                    default:
                        break;
                }
                if ($re) {
                    if (empty($re['code'])) {
                        $this->out_arr['rows']=$re;
                        $this->out_arr['error_code'] = "000000";
                        $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                    }else{
                        $this->out_arr['error_code'] = $re['code'];
                        $this->out_arr['error_text'] = $re['msg'];
                    }
                }else{
                    $this->out_arr['error_code'] = "110004";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }
            }else{
                $this->out_arr['error_code'] = $order['code'];
                $this->out_arr['error_text'] = $order['msg'];
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //快件跟踪
    public function orderTrack($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('ordernum'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [];
            $ordernum=$this->arr["ordernum"];
            $param = "?command=getOrderIdByNum&ordernum=".$ordernum;
            $option = "index".$param;
            $order = $this->rest($mothed,$body,$header,$option);
            // var_dump($order);exit();
            if (empty($order['code'])) {
                $param = "?command=statusList&orderid=".$order['rows']['f_orderid'];
                $option = "index".$param;
                $re = $this->rest($mothed,$body,$header,$option);
                
                if ($re) {
                    if ($re['code']=='000000') {
                        $this->out_arr['rows']=$re['response'];
                        $this->out_arr['f_ordernum']=$this->arr["ordernum"];
                        $this->out_arr['f_createtime']=date('Y-m-d H:i:s',$order['rows']['f_createtime']);
                        $this->out_arr['error_code'] = "000000";
                        $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                    }else{
                        $this->out_arr['error_code'] = $re['code'];
                        $this->out_arr['error_text'] = $re['msg'];
                    }
                }else{
                    $this->out_arr['error_code'] = "110004";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }
            }else{
                $this->out_arr['error_code'] = $order['code'];
                $this->out_arr['error_text'] = $order['msg'];
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //地址详情
    public function addressNote($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('addrid'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $addrid=$this->arr["addrid"];
            $param = "?command=addressNote&addrid=".$addrid;
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            if ($re) {
                if (empty($re['code'])) {
                    $this->out_arr['rows'] = $re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //消息列表
    public function newsList($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('page','pagesize'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $page=$this->arr["page"];
            $pagesize=$this->arr["pagesize"];
            $userId=isset($this->arr["userId"])?$this->arr["userId"]:"";
            $param = "?command=newsList&page=".$page."&pagesize=".$pagesize."&pagesize=".$pagesize."&userid=".$userId;
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            if ($re) {
                if (empty($re['code'])) {
                    $this->out_arr=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //商户详情
    public function userNote($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('userId'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [
            ];
            $page=empty($this->arr["page"])?1:$this->arr["page"];
            $pagesize=empty($this->arr["pagesize"])?10:$this->arr["pagesize"];
            $userId=$this->arr["userId"];
            $param = "?command=userNote&page=".$page."&pagesize=".$pagesize."&uid=".$userId;
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            unset($re['detailNote']);
            unset($re['f_regdate']);
            unset($re['f_workstatus']);
            unset($re['f_open_user']);
            unset($re['f_merchant_id']);
            unset($re['f_moditime']);
            unset($re['f_balance']);
            unset($re['f_credit']);
            unset($re['f_integral']);
            unset($re['f_creditlimit']);
            unset($re['f_printid']);
            unset($re['f_callback']);
            unset($re['f_tokenurl']);
            unset($re['f_orderurl']);

            unset($re['price']);
            unset($re['total']);
            unset($re['page']);
            unset($re['pagesize']);
            unset($re['pagetotal']);
            unset($re['rows']);
            if ($re) {
                if (empty($re['code'])) {
                    $this->out_arr['rows']=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //网点列表
    public function nodeListByCity($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('pCompanyId'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [];
            $param = "?command=nodeListByCity&page=1&pagesize=100&companyid=".$this->arr['pCompanyId'];
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            if ($re) {
                if ($re['code']!=='300000') {
                    $this->out_arr['response']['ningbo']=$re['宁波市'];
                    $this->out_arr['response']['hanhzhou']=$re['杭州市'];
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    //关联公司列表
    public function companyRelationList($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('action_companyId'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [];
            $param = "?command=companyRelationList&page=1&pagesize=10&searchType=1&companyid=".$this->arr['action_companyId'];
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);
            if ($re) {
                if ($re['code']!=='300000') {
                    $this->out_arr=$re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }

    // //支付流水
    public function moneyList($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $bool = $this->is_empty(array('userId'),$this->arr);
        if($bool){
            $mothed = 'GET';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];
            $body = [];
            $userId=$this->arr["userId"];
            $companyid=$this->arr["action_companyId"];
            $page=empty($this->arr["page"])?1:$this->arr["page"];
            $pagesize=empty($this->arr["pagesize"])?10:$this->arr["pagesize"];
            $payerType=empty($this->arr["payerType"])?3:$this->arr["payerType"];
            $param = "?command=moneyList&page=".$page."&pagesize=".$pagesize."&uid=".$userId."&companyid=".$companyid."&payerType=".$payerType;
            $option = "index".$param;
            $re = $this->rest($mothed,$body,$header,$option);

            $param = "?command=userDetailSearch&userId=".$userId;
            $option = "index".$param;
            $user = $this->rest($mothed,$body,$header,$option);
            $re['f_balance']=$user['f_balance'];
            // dump($re);exit();
            foreach ($re['rows'] as $key => $value) {
                unset($re['rows'][$key]['f_openid']);
                unset($re['rows'][$key]['f_tranaction_id']);
                unset($re['rows'][$key]['f_companyid']);
                if ($value['f_back']=='支付'||$value['f_back']=='减少授信') {
                    $re['rows'][$key]['f_count']='-'.$value['f_count'];
                }elseif($value['f_back']=='退款'||$value['f_back']=='充值'||$value['f_back']=='还款'||$value['f_back']=='增加授信'){
                    $re['rows'][$key]['f_count']='+'.$value['f_count'];
                }
            }
            if ($re) {
                if ($re['code']!=='300000') {
                    $this->out_arr = $re;
                    $this->out_arr['error_code'] = "000000";
                    $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                }else{
                    $this->out_arr['error_code'] = $re['code'];
                    $this->out_arr['error_text'] = $re['msg'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }

        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }

        return $this->out_arr;
    }


    //检验支付是否成功 
    public function checkAppPay($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('aid'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'checkAppPay',
                'aid'=>$this->arr['aid'],
            ];
            
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
            
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    //公司列表
    public function getCompanyList($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $mothed = 'GET';
        $header = [
            'token:'.cookie('token'),
            'appid:'.C("appid")
        ];
        $body = [];
        $companyType=empty($this->arr['companyType'])?'carry_company':$this->arr['companyType'];
        $param = "?command=getCompany&companyType=".$companyType;
        $option = "index".$param;
        $re = $this->rest($mothed,$body,$header,$option);
        if ($re) {
            if ($re['code']!=='300000') {
                $this->out_arr['error_code'] = "000000";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                $this->out_arr['response']=$re['response'];
            }else{
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
            }
        }else{
            $this->out_arr['error_code'] = "110004";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        
        return $this->out_arr;
    }

    public function getCidBySubname($jsonString)
    {
        //解密数据
        $this->arr = $this->decode($jsonString);
        //必传参数检查
        $mothed = 'GET';
        $header = [
            'token:'.cookie('token'),
            'appid:'.C("appid")
        ];
        $body = [];
        $param = "?command=getCidBySubname&subname=".$this->arr['subname'];
        $option = "index".$param;
        $re = $this->rest($mothed,$body,$header,$option);
        if ($re) {
            if ($re['code']!=='300000') {
                $this->out_arr['error_code'] = "000000";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
                $this->out_arr['response']=$re;
            }else{
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
            }
        }else{
            $this->out_arr['error_code'] = "110004";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        
        return $this->out_arr;
    }


    //用户是否已经认证过 
    public function userCertification($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('userId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'userCertification',
                'userid'=>$this->arr['userId'],
                'companyid'=>empty($this->arr['action_companyId'])?0:$this->arr['action_companyId'],
            ];
            // empty($this->arr['action_companyId'])?'':$body['companyid']=$this->arr['action_companyId'];
            empty($this->arr['pCompanyId'])?'':$body['pcompanyid']=$this->arr['pCompanyId'];
            
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                // if ($re['code']=='000000') {
                    $this->out_arr['response']=$re['response'];
                // }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
            
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }


    //个人实名认证接口 
    public function runUserCertification($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('idcardNum','idcardName','userId','pCompanyId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'runUserCertification',
                'idcardNum'=>$this->arr['idcardNum'],
                'idcardName'=>$this->arr['idcardName'],
                'userid'=>$this->arr['userId'],
                'file'=>empty($this->arr['file'])?'':$this->arr['file'],
                'pcompanyid'=>$this->arr['pCompanyId'],
                'platform'=>'yonghu',
            ];
            
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=='000000') {
                    $this->out_arr['response']=$re['response'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
            
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }


    //公司营业执照认证 
    public function runCompanyCertification($jsonString){
        //解密数据
        $this->arr = $this->decode($jsonString);
         //必传参数检查
        $bool = $this->is_empty(array('action_companyId','type','cardnum','userId','pCompanyId'),$this->arr);
        if($bool){
            $mothed = 'POST';
            $header = [
                'token:'.cookie('token'),
                'appid:'.C("appid")
            ];

            $body = [
                'command'=>'runCompanyCertification',
                'companyid'=>$this->arr['action_companyId'],
                'file'=>isset($this->arr['file'])?$this->arr["file"]:'',
                'type'=>isset($this->arr["type"])?$this->arr["type"]:1,//认证类型（3为公司身份证认证，1为公司营业执照认证）
                'realName'=>isset($this->arr['realName'])?$this->arr["realName"]:'',
                'cardnum'=>$this->arr["cardnum"],//认证号码，如果type为3传身份证号，为1传营业执照号
                'userid'=>$this->arr["userId"],//当前用户ID
                'pcompanyid'=>empty($this->arr["pCompanyId"])?1:$this->arr["pCompanyId"],
            ];
            
            $re = $this->rest($mothed,$body,$header);
            if ($re) {
                $this->out_arr['error_code'] = $re['code'];
                $this->out_arr['error_text'] = $re['msg'];
                if ($re['code']=='000000') {
                    $this->out_arr['response']=$re['response'];
                }
            }else{
                $this->out_arr['error_code'] = "110004";
                $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
            }
            
        }else{
            $this->out_arr['error_code'] = "900003";
            $this->out_arr['error_text'] = A("Error")->searchCode($this->out_arr['error_code']);
        }
        return $this->out_arr;
    }

    
//-------------------------------------------------CURL函数------------------------------------------

    /**
     * CURL提交
     * @param $mothed
     * @param $body
     * @param $header
     */
    function rest($mothed,$body,$header,$option='index'){
        $header[2]='Content-Type:application/json;charset=utf-8';
        $url = C("submit_url").$option;
        $ch = curl_init();
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_HEADER, false );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 120 );
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
        if($mothed!="GET"){
            curl_setopt ( $ch, CURLOPT_POSTFIELDS, json_encode($body) );
        }
        curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, $mothed );
        $return = curl_exec ( $ch );
        // echo $return;
        curl_close ( $ch );
        return json_decode($return,true);
    }


    /**
    * 输出xml字符
    * @param $params 参数名称
    * return string 返回组装的xml
    **/
    public function data_to_xml($params){
        if(!is_array($params)|| count($params) <= 0){
            return false;
        }
        $xml = "<xml>";
        foreach ($params as $key=>$val){
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        return $xml; 
    }

}